package Escola;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import Endereco.Endereco;

@Entity
@Table (name = "tab_escola")
public class Escola implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue (strategy = GenerationType.IDENTITY)
	@Column (unique = true, nullable = false)
	private Integer codEscola;
	
	@Column (length = 50)
	private String dscEscola;
	
	@ManyToOne (fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
	private Endereco endereco;

	public Escola() {
		super();
	}

	public Escola(String dscEscola, Endereco endereco) {
		super();
		this.dscEscola = dscEscola;
		this.endereco = endereco;
	}

	public Integer getCodEscola() {
		return codEscola;
	}

	public void setCodEscola(Integer codEscola) {
		this.codEscola = codEscola;
	}

	public String getDscEscola() {
		return dscEscola;
	}

	public void setDscEscola(String dscEscola) {
		this.dscEscola = dscEscola;
	}

	public Endereco getEndereco() {
		return endereco;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((codEscola == null) ? 0 : codEscola.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Escola other = (Escola) obj;
		if (codEscola == null) {
			if (other.codEscola != null)
				return false;
		} else if (!codEscola.equals(other.codEscola))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return dscEscola ;
	}
	
	
}
